< previous page page_306 next page >

Page 306
As you learned in earlier chapters, you can combine the controls included with Visual Basic to build a powerful application quickly. One of the most exciting features of Visual Basic is the ability to create your own controls. These programmer-built controls, also known as ActiveX controls, can then be used in Visual Basic applications like any other control. (ActiveX is a Microsoft term that refers to a group of components that include controls, DLLs, and ActiveX documents.) In addition to the obvious advantage of reusing code, ActiveX controls can be used on a Web page to deliver program-like functionality over the Internet.
In this chapter, you take a look at the various approaches you can take and some of the issues that you need to consider when creating ActiveX controls. The information contained in this chapter is then further expanded in the following chapter, "Extending ActiveX Controls," which teaches you how to build more robust ActiveX controls.
ActiveX Basics
You are familiar with controls such as the TextBox and Label controls. To use these controls, you draw them on a form and control their behavior through properties, methods, and events. When you create your own ActiveX control, you are creating a similar object, except you are determining the properties, methods, and events. After you create your own ActiveX control, you and others can use it in other Visual Basic projects, just like a TextBox control. You can use your controls in any application or development tool that can use ActiveX controls, including other Visual Basic projects or Microsoft Internet Explorer. In fact, using ActiveX controls is an ideal way to create a reusable component that can be used both inside a traditional client/server EXE and on the Internet.
Steps Involved in Building ActiveX Controls
Creating an ActiveX control in Visual Basic is different from creating a Standard EXE application. Therefore, a brief overview of the steps involved is useful:
1. Create a high-level design to determine what you want your ActiveX control to do. An ActiveX control is like a standalone object, so you need to ask yourself what purpose does the object serve? What appearance do you want it have onscreen? What properties, methods, and events need to be made available to the program using the control?
2. Determine whether you will be using other controls as building blocks for your control. For example, you might want to create an ActiveX control that includes a third-party grid. When you are using other controls within your control, consider licensing and distribution issues.
3. Start a new Visual Basic ActiveX control project, and draw the interface for your control.
4. Add code to enable all the properties, methods, and events you want your control to have.
5. Build a test project, and test your control from within Visual Basic. Make sure to use all the properties, methods, and events that you give your control.
6. Compile your control into an OCX file, and perform testing on the compiled version of your control. If you are developing for the Internet, test your control on a Web page.

 
< previous page page_306 next page >